angular.module('fruitMod',[])
.controller('fruitCtrl',['$scope','$http','cart','total',function($scope,$http,cart,total){
	$scope.fruitList = [];
	$scope.text = '';
	$http({
		url: 'http://h5.yztctech.net/api/axf/apicategory.php?',
		method: "get",
		params: {
			'category': '优选水果'
		}
	}).success(function(res){
		res.text = '优选水果';
		$scope.fruitList = res.data;
		$scope.text = '优选水果';
	})

	//先声明一个变量来存储数据
	var obj = {};
	$scope.addFun = function(i){
		// console.log($scope.text);
		if(!i.num){
			i.num = 1;
		}else{
			i.num ++;
			
		}
		cart.addFun(i,$scope.text);
		// if (window.localStorage.cart) {
		// 	obj = JSON.parse(window.localStorage.cart);
		// }
		// obj[text+''+i.id] = i;
		// window.localStorage.setItem("cart",JSON.stringify(obj));
		total.fun();
	}

	$scope.delFun = function(i){
		i.num--;
		if (i.num<=0) {
			console.log(111)
			cart.delFun($scope.text+''+i.id);
		}
		total.fun();
	}
}])